__app.define('aorder_VM_Extend.js', function () {
  var objVm = ''
  var aorder_VM_Extend = {
    afterInitOrder: function(obj){
      objVm = obj.vm
    },
    afterSelectShippingAddr: function(opt){
      console.log("after",opt)
      if(opt.data.oOrderDetails.length != 0) {
        opt.data.oOrderDetails.splice(0,2)
        editPrice(opt.data)
      }
      function editPrice(data) { 
        let obj = {
          customer: window.__app.mainV.$store.getters.currentUser.agentId,
          deliveryMethod: '厂送',
          receiveAddress: opt.shippingAddr.receiveAddress,
          productDetail: [],
        }
        data.oOrderDetails.forEach(element => {
          let product = {
            productCode: '',
            productId: element.iProductId,
            org: element.salesOrgId,
            priceQty: element.iQuantity,
            productUnitId: element.productUnitId,
            currency: '1655486829428736015',
            stockId: ''
          }
          obj.productDetail.push(product)
        });
        const url = 'https://saas.hlhs-bip.com/iuap-api-gateway/ajxbewdh/AcquisitionPrice/GetPriceAndFreight/pricing/acquisitionPrice?appKey=a4dc65b0fbab4f68a56e8054999a2ab3'
        __app.ajax({
          type: "POST",
          data: obj,
          url: url,
          success: function (res) {
            opt.data.oOrderDetails.forEach((item,index) => {
              item.fTransactionPrice += res[item.iProductId].freight 
              item.fSalePayMoney += res[item.iProductId].freight *item.iQuantity //含税金额
              item.modifyPriceStatus = 1
              item.oOrderDetailDefine.define3 = res[item.iProductId].freight 
            })
            // opt.data.oOrderDetails[0].fSalePrice += 55 //含税报价
            // opt.data.oOrderDetails[0].fTransactionPrice += res.freight //含税成交价
            // opt.data.oOrderDetails[0].modifyPriceStatus = 1
            // opt.data.oOrderDetails[0].oOrderDetailDefine.define3 = 55
            // opt.data.oOrderDetails[0].saleCostOrigTaxfree += res.freight //报价无税金额
            // opt.data.oOrderDetails[0].salePriceOrigTaxfree += res.freight //无税报价
            // opt.data.oOrderDetails[0].transactionPriceOrigTaxfree += res.freight //无税成交价
            // // opt.data.oOrderDetails[0].oriTax += res.freight //税额
            // opt.data.oOrderDetails[0].salePayMoneyOrigTaxfree += res.freight //无税金额
            // opt.data.fTotalMoney += res.freight //商品全额
            // opt.data.bClearGiveaway = true
            // opt.data.oOrderDetails[0].fSaleCost += res.freight //报价含税金额
            objVm.adjustOrder({ data: opt.data, clearGiveaway: true, loading: true });
            // debugger
          },
          error: function (error) {
          }
        })
      }
    } 
  };
  return aorder_VM_Extend;
});